<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        ul li:first-child .up{
            display: none;
        }
        ul li:last-child .down{
            display:none;
        }
    </style>
</head>
<body>
    <ul>
        <li>
            <input type="text" value="姓名" style="color: red">
            <a class="up" href="javascript:void(0)">向上</a>
            <a class="down" href="javascript:void(0)">向下</a>
        </li>
        <li>
            <input type="number" id="phone" value="电话" style="color: green">
            <a class="up" href="javascript:void(0)">向上</a>
            <a class="down" href="javascript:void(0)">向下</a>
        </li>
        <li>
            <input type="text" value="邮箱" style="color: hotpink">
            <a class="up" href="javascript:void(0)">向上</a>
            <a class="down" href="javascript:void(0)">向下</a>
        </li>
        <li>
            <input type="text" value="地址">
            <a class="up" href="javascript:void(0)">向上</a>
            <a class="down" href="javascript:void(0)">向下</a>
        </li>
        <li class="add">添加</li>
    </ul>
    <script src="./js/jquery.min.js"></script>
    <script>

        $(function() {
            $('.up').on('click', function() {
                var idx = $(this).parentsUntil('ul').index();
                var new_idx = idx - 1;
                var liObj = $('li').eq(new_idx);//上一个元素
                $($(this).parentsUntil('ul')).after(liObj);
            });
            $('.down').on('click', function() {
                var idx = $(this).parentsUntil('ul').index();
                var new_idx = idx + 1;
                // var liObj = $('li').eq(new_idx);//下一个元素
                var liObj = $(this).parentsUntil('ul').next();
                $($(this).parentsUntil('ul')).before(liObj);
            });
        });
        $('.add').on('click', function() {
            if($('#phone').val()<1){
                console.log($('#phone').val())
            }
        });
        
    </script>
</body>
</html>
